package cn.eports.learn.web.servlet;

import cn.eports.learn.service.UserService;
import cn.eports.learn.service.impl.UserServiceImpl;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

@WebServlet("/deleteUserServlet")
public class DeleteUserServlet extends HttpServlet {

    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        this.doPost(req, resp);
    }

    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
//        super.doPost(req, resp);
        // 1. 获取要删除的数据的id
        final String id = req.getParameter("id");

        // 2. 调用service处理数据
        UserService service = new UserServiceImpl();
        service.deleteUser(id);

        //3. 跳转到userListServlet
        resp.sendRedirect(req.getContextPath() + "/userListServlet");



    }
}
